package com.ckg.service.impl;

import com.ckg.service.PaymentGateway;
import com.ckg.service.SmsService;

// 支付服务（混合使用两种注入方式）
public class PaymentService {
    private final PaymentGateway paymentGateway; // 强制依赖（构造器注入）
    private SmsService smsService; // 可选依赖（Setter注入）

    // 构造器注入强制依赖
    public PaymentService(PaymentGateway paymentGateway) {
        this.paymentGateway = paymentGateway;
    }

    // Setter注入可选依赖
    public void setSmsService(SmsService smsService) {
        this.smsService = smsService;
    }

    public void makePayment(double amount, String phone) {
        paymentGateway.processPayment(amount);

        if (smsService != null) {
            smsService.sendSms(phone,
                    String.format("支付成功: %.2f元", amount));
        }
    }
}